<?php
namespace Users\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Expression;
class UsernewsletterTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function addUsersNewsletter($subscribe_id,$news_id)
    {
		$data = array(
			'subscribe_id'       => $subscribe_id, 	
			'newsletter_id' 	 => $news_id,
			'status' 		     => 0, 
			'added_date' 	     => date('Y-m-d H:i:s'), 							
		);		
		$this->tableGateway->insert($data);
		return $this->tableGateway->lastInsertValue;
    }
	public function checkNewsLetterSend($email_id,$news_id){
		//echo "<pre>";print_r($news_id);exit;
		$select = $this->tableGateway->getSql()->select();			
		$select->where('subscribe_id="'.$email_id.'"');	
		$select->where('newsletter_id="'.$news_id.'"');	
		$resultSet = $this->tableGateway->selectWith($select);
		$row=$resultSet->count();	
		return $row;		
	}
}